/*###################################################################*
#
# MPGL Engine - CrossPlatform OpenGL Engine
# Copyright (C) 2014  Mitchell Pell
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
####################################################################*/

#ifndef GL_INPUT_MANAGER_H
#define GL_INPUT_MANAGER_H

#include "GLButtonEventCollection.h"
#include "GLDirectKeyboardInput.h"

/*! Include Updateable Template Header */
#include "../../../Base/Updateable.h"

#define MPGL_DEF_DIRECTKEY_LISTENETS 1

using namespace mp_base::interfaces;

namespace mpgl_engine{ namespace application{
		/*! @brief Application level, Input Manager. */
		namespace input {
	
	/*!----------------------------------------------------------------
	*	@class		GLInputManager
	*	@brief		This object manages both button events from the 
	*				keyboard and mouse, and synced values like the
	*				mouse location and the mouses scroll wheel
	*				location.
	*
	*	@author		Mitchell Pell
	*	@date		10/2/2013
	*	@version	1.1
	*	@revisions	Revision History:
	*					- Version 1.1 10/2/2013
	*						-# Added support for direct keyboard
	*							char input.
	*					- Version 1.0 9/27/2013
	*						-# Initial Make
	*
	-----------------------------------------------------------------*/
	class GLInputManager : Updateable
	{
		/*! Bound window to listen to. */
		GLFWwindow*					m_window;
		/*! Collection of defined key press events. */
		GLButtonEventCollection*	m_inputBindCollection;
		/*! Collection of direct keyboard char listeners */
		GLDirectKeyboardInput**		m_directKeyInputs;
		/*! Number of direct keyboard char listeners bound */
		unsigned int				m_directKeyInputCount;
		

	public:
		/*! Default constructor */
		GLInputManager(GLFWwindow* window);
		~GLInputManager();		

		/*! Initialization called by GLApp */
		void Initialize();
		/*! Update called by GLApp */
		void Update();
		/*! Uninitialization called by GLApp */
		void Uninitialize();	

		/*! Sets the listening GLFWwindow */
		void SetWindow(GLFWwindow* window){m_window = window;}
		/*! Gets the listening GLFWwindow */
		GLFWwindow* GetWindow(){return m_window;}

		/*! Gets the button press collection */
		GLButtonEventCollection* GetInputEventCollection()
			{return m_inputBindCollection;}
		
		/*!  */
		void AddDirectKeyboardListener
			(GLDirectKeyboardInput* listener);
		/*! Binds a direct keyboard char listener */
		void BindDirectKeyboardListener();		
		/*! Called by GLFW libraries whenever a char event is
			passed from the keyboard. */
		static void KeyCharEvent(GLFWwindow* window, unsigned int key);
		/*! Called by KeyCharEvent to distribute the event
			to all the listeners.*/
		void SendGLDirectKeyboardEvent(unsigned int key);


	};
}}}

#endif